<template>
    <div class="wrap normal">
        <!-- 搜索条件 -->
        <div class="wrap-form" id="wrap-form">
            <div class="left-panel">
                <el-form :inline="true" :model="form" label-width="80px" @submit.native.prevent>
                    <el-form-item label="提现类型">
                        <el-select v-model="form.billOrder" placeholder="请选择" clearable style="width: 220px">
                            <el-option v-for="(item, index) in billPayOptions" :key="index" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="pageOperate('search')">查询</el-button>
                        <el-button icon="el-icon-refresh" @click="pageOperate('refresh')">刷新</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <!-- 列表 -->
        <div class="wrap-table">
            <el-table :data="tableData" :max-height="tableMaxHeight" border v-loading="tableLoading" :header-cell-style="{ background: '#F5F6FA' }">
                <el-table-column type="index" label="序号" width="50" align="center"> </el-table-column>
                <el-table-column prop="courierNumber" label="快递单号" min-width="160"> </el-table-column>
                <el-table-column prop="parcelStatus" label="订单状态" min-width="120"> </el-table-column>
                <el-table-column prop="parcelOrderUserData" label="用户数据" min-width="120"> </el-table-column>
                <el-table-column prop="finallyPlaceOrderData" label="计费数据" min-width="120"> </el-table-column>
                <el-table-column prop="finallyMoneyData" label="利润数据" min-width="120"></el-table-column>
                <el-table-column label="下单时间" min-width="140">
                    <template slot-scope="scope">
                        {{ scope.row.parcelOrderDate | iso8601DateTimeFormat }}
                    </template>
                </el-table-column>
                <el-table-column label="计费时间" min-width="140">
                    <template slot-scope="scope">
                        {{ scope.row.billOrderDate | iso8601DateTimeFormat }}
                    </template>
                </el-table-column>
            </el-table>
            <pagination :total="page.totalNum" :page.sync="page.pageNum" :limit.sync="page.pageSize" layout="total, sizes, prev, pager, next, jumper" @pagination="getTableData" />
        </div>
        <!-- 操作 -->
        <el-dialog v-if="operateDialog" :title="operateTitle" :visible.sync="operateDialog" @close="closeOperateDialog" :width="`${operateWidth}px`" :close-on-press-escape="false" :close-on-click-modal="false">
            <div slot="footer" class="dialog-footer">
                <el-button @click="closeOperateDialog">取 消</el-button>
                <el-button type="primary" :loading="operateLoading" @click="operateSubmit">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import tableHeight from '@/mixins/tableHeight'
import { getPackageList } from '@/api/fund'
import { billPayOptions } from '@/filters/options'
export default {
    name: 'PackageHistory',
    mixins: [tableHeight],
    data() {
        return {
            form: {
                billOrder: ''
            },
            page: {
                pageNum: 1,
                pageSize: 10,
                totalNum: 0
            },
            tableData: [],
            tableLoading: false,
            // 类型
            operateType: '',
            // 标题
            operateTitle: '',
            // 弹框
            operateDialog: false,
            // 宽度
            operateWidth: 550,
            // loading
            operateLoading: false,
            // 操作form
            operateForm: {},
            operateRules: {},
            // 计费状态
            billPayOptions
        };
    },
    methods: {
        // 数据
        getTableData() {
            this.tableLoading = true
            const data = {
                pageNum: this.page.pageNum,
                pageSize: this.page.pageSize,
                ...this.form
            }
            getPackageList(data).then(res => {
                this.tableLoading = false
                this.tableData = res.data.records
                this.page.totalNum = res.data.total
            }).catch(error => {
                this.tableLoading = false
            })
        },
        // 操作
        pageOperate(type, row) {
            this.operateType = type
            switch (type) {
                case 'search':
                    this.getTableData()
                    break;
                case 'refresh':
                    Object.assign(this.$data, this.$options.data())
                    this.getTableData()
                    break;
                default:
                    break;
            }
        },
        // 关闭弹框
        closeOperateDialog() {
            this.operateLoading = false
            this.operateDialog = false
            this.operateType = ''
            this.operateTitle = ''
            this.operateForm = this.$options.data().operateForm
        },
        // 操作提交
        operateSubmit() {
            this.$refs.operateForm.validate(valid => {
                if (valid) { }
            })
        }
    },
    mounted() {
        this.getTableData()
    }
};
</script>

<style lang="scss" scoped>
::v-deep {
    .el-table {
        .cell {
            white-space: pre-line;
        }
    }
}
</style>